package com.keiou.drink.util;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

import com.keiou.drink.AppContext;


/**
 * 作者 ：Bob on 2017/6/2.
 * 邮箱 ：motherlovefather@126.com
 */

public class UIUtil {


    /**
     * activity跳转
     *
     * @param context
     * @param clazz
     */
    public static void redirectTo(Context context, Class<?> clazz) {
        Intent intent = new Intent(context, clazz);
        context.startActivity(intent);
    }


    /**
     * 隐藏软键盘
     *
     * @param activity
     */
    public static void hideSoftKeyboard(Activity activity) {
        if (null != activity) {
            View view = activity.getCurrentFocus();
            if (null != view)
                ((InputMethodManager) AppContext.getInstance().getSystemService(
                        Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(
                        view.getWindowToken(), 0);
        }
    }

    public static void hideSoftKeyboard(View view) {
        if (null != view)
            ((InputMethodManager) AppContext.getInstance().getSystemService(
                    Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(
                    view.getWindowToken(), 0);
    }


}
